package com.salt.admin.api.feign.hystrix;

import com.salt.admin.api.feign.client.DictClient;
import com.salt.admin.api.model.DictValue;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description 字典（后台管理中心）远程调用失败处理类
 * @Author salt
 * @Date 2020/8/18 16:32
 * @Version 1.0
 */
@Slf4j
@Component
public class DictClientHystrix implements FallbackFactory<DictClient> {

    @Override
    public DictClient create(Throwable throwable) {

        String message = throwable.getMessage() == null ?
                "No available server for client: ADMIN-CENTER" :
                throwable.getMessage();
        log.info("Hystrix:{}", message);

        return new DictClient() {

            @Override
            public String getDictValue(String label, String type, String defaultLabel) {
                log.info("--查询字典值异常, label: " + label + " ,type: " + type + " ,defaultLabel: " + defaultLabel);
                return null;
            }

            @Override
            public String getDictLabel(String value, String type, String defaultLabel) {
                log.info("--查询字典标签异常, label: " + value + " ,type: " + type + " ,defaultLabel: " + defaultLabel);
                return null;
            }

            @Override
            public List<DictValue> getDictList(String type) {
                log.info("--查询字典类型异常, type: " + type);
                return null;
            }
        };
    }
}
